home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 124 / cd-rom 124.iso / edu / tuxmath / tuxmathscrabble / tuxmathscrabble.exe / asymptopia / Board.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-11-16  |  6.4 KB  |  187 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.2)
  3.  
  4. import pygame
  5. from pygame.locals import *
  6. from Spot import Spot
  7.  
  8. class Board(pygame.sprite.Group):
  9.     
  10.     def __init__(self, M, N, XC, YC, background_image, default_spot_image):
  11.         pygame.sprite.Group.__init__(self)
  12.         self.M = M
  13.         self.N = N
  14.         self.XC = XC
  15.         self.YC = YC
  16.         self.default_spot_image = default_spot_image
  17.         self.map = None
  18.         self.num_commited = 0
  19.         if background_image and not default_spot_image:
  20.             self.make_background_spots(background_image)
  21.         elif default_spot_image and not background_image:
  22.             self.make_default_spots(default_spot_image)
  23.         else:
  24.             self.make_invisible_spots(None)
  25.  
  26.     
  27.     def get_map(self):
  28.         m = []
  29.         for midx in range(self.M):
  30.             m.append([])
  31.             for nidx in range(self.N):
  32.                 for spot in self.sprites():
  33.                     if spot.getMN()[0] == midx and spot.getMN()[1] == nidx:
  34.                         if spot.guest:
  35.                             m[midx].append(spot.guest.str_val)
  36.                         else:
  37.                             m[midx].append('')
  38.                     
  39.                 
  40.             
  41.         
  42.         return m
  43.  
  44.     
  45.     def check4guest(self, m, n):
  46.         if m < 0 and m > self.M - 1 and n < 0 or n > self.N - 1:
  47.             return 0
  48.         
  49.         spot = self.get_spotMN(m, n)
  50.         if spot.guest == None:
  51.             return 0
  52.         else:
  53.             return 1
  54.  
  55.     
  56.     def get_listofheads(self):
  57.         heads = []
  58.         for spot in self.sprites():
  59.             if spot.guest:
  60.                 if spot.AMHEAD:
  61.                     heads.append(spot)
  62.                 
  63.             
  64.         
  65.         return heads
  66.  
  67.     
  68.     def clear_spots(self):
  69.         for spot in self.sprites():
  70.             spot.remove(self)
  71.         
  72.  
  73.     
  74.     def get_spotMN(self, m, n):
  75.         for spot in self.sprites():
  76.             MN = spot.getMN()
  77.             if MN[0] == m and MN[1] == n:
  78.                 return spot
  79.             
  80.         
  81.  
  82.     
  83.     def take_guestMN(self, tile, m, n):
  84.         for spot in self.sprites():
  85.             MN = spot.getMN()
  86.             if MN[0] == m and MN[1] == n:
  87.                 spot.take_guest(tile, 1)
  88.                 return spot
  89.             
  90.         
  91.  
  92.     
  93.     def get_num_commited(self):
  94.         return self.num_commited
  95.  
  96.     
  97.     def increment_num_commited(self):
  98.         self.num_commited = self.num_commited + 1
  99.  
  100.     
  101.     def get_guest_by_str(self, str_val):
  102.         for spot in self.sprites():
  103.             if spot.guest and spot.guest.str_val == str_val:
  104.                 return spot.pop_guest()
  105.             
  106.         
  107.         return None
  108.  
  109.     
  110.     def get_spots(self):
  111.         return self.sprites()
  112.  
  113.     
  114.     def make_background_spots(self, background_image):
  115.         for midx in range(self.M):
  116.             for nidx in range(self.N):
  117.                 self.add(Spot(default_spot_image, midx, nidx))
  118.             
  119.         
  120.  
  121.     
  122.     def make_default_spots(self, default_spot_image):
  123.         XC = self.XC
  124.         YC = self.YC
  125.         M = self.M
  126.         N = self.N
  127.         for midx in range(0, M):
  128.             for nidx in range(0, N):
  129.                 if self.M == 1:
  130.                     spot = Spot(default_spot_image, midx, nidx, 'REG')
  131.                 elif abs(M / 2 - midx) == abs(N / 2 - nidx):
  132.                     img = default_spot_image[:-4] + '_2XL.gif'
  133.                     spot = Spot(img, midx, nidx, '2XL')
  134.                 elif midx == -nidx + (N / 2 - 4):
  135.                     img = default_spot_image[:-4] + '_3XL.gif'
  136.                     spot = Spot(img, midx, nidx, '3XL')
  137.                 elif midx == -nidx + N / 2 + 16:
  138.                     img = default_spot_image[:-4] + '_3XL.gif'
  139.                     spot = Spot(img, midx, nidx, '3XL')
  140.                 elif midx == +nidx - (N / 2 + 4):
  141.                     img = default_spot_image[:-4] + '_3XL.gif'
  142.                     spot = Spot(img, midx, nidx, '3XL')
  143.                 elif midx == +nidx + 8:
  144.                     img = default_spot_image[:-4] + '_3XL.gif'
  145.                     spot = Spot(img, midx, nidx, '3XL')
  146.                 elif not midx == 0 and nidx == 0:
  147.                     if not nidx == N - 1 and midx == M - 1:
  148.                         if nidx == 0 and midx == M - 1 and nidx == N - 1 and midx == 0:
  149.                             img = default_spot_image[:-4] + '_2XW.gif'
  150.                             spot = Spot(img, midx, nidx, '2XW')
  151.                         elif not midx == M / 2 and nidx == N / 4:
  152.                             if not nidx == N / 2 and midx == M / 4:
  153.                                 if nidx == N / 2 and midx == 3 * M / 4 and nidx == 3 * N / 4 and midx == M / 2:
  154.                                     img = default_spot_image[:-4] + '_2XW.gif'
  155.                                     spot = Spot(img, midx, nidx, '2XW')
  156.                                 elif nidx == N / 2 and midx == 0:
  157.                                     img = default_spot_image[:-4] + '_3XW.gif'
  158.                                     spot = Spot(img, midx, nidx, '3XW')
  159.                                 elif nidx == N / 2 and midx == M - 1:
  160.                                     img = default_spot_image[:-4] + '_3XW.gif'
  161.                                     spot = Spot(img, midx, nidx, '3XW')
  162.                                 elif nidx == 0 and midx == M / 2:
  163.                                     img = default_spot_image[:-4] + '_3XW.gif'
  164.                                     spot = Spot(img, midx, nidx, '3XW')
  165.                                 elif nidx == N - 1 and midx == M / 2:
  166.                                     img = default_spot_image[:-4] + '_3XW.gif'
  167.                                     spot = Spot(img, midx, nidx, '3XW')
  168.                                 else:
  169.                                     spot = Spot(default_spot_image, midx, nidx, 'REG')
  170.                 w = spot.image.get_width()
  171.                 h = spot.image.get_height()
  172.                 spot.rect.center = (XC + (-N / 2 + nidx + 0.5) * w, YC + (-M / 2 + midx + 0.5) * h)
  173.                 self.add(spot)
  174.             
  175.         
  176.  
  177.     
  178.     def make_invisible_spots(self, invisible):
  179.         print 'make_invisible_spots'
  180.         for midx in range(self.M):
  181.             for nidx in range(self.N):
  182.                 self.add(Spot(invisible, midx, nidx))
  183.             
  184.         
  185.  
  186.  
  187.